package com.topvision.controller.glass;

import java.util.List;
import java.util.Map;

import com.topvision.constants.TopVisionWebConstants;
import com.topvision.controller.AbstractController;
import com.topvision.model.glass.Equipment;
import com.topvision.service.glass.EquipmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;

/**
 * @author shengwm
 * @email 179653076@qq.com
 * @date 2017-08-03 11:02:04
 */
@RestController
@RequestMapping("equipment")
public class EquipmentController extends AbstractController {
    @Autowired
    private EquipmentService equipmentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("equipment:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<Equipment> equipmentList = equipmentService.queryList(query);
        int total = equipmentService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(equipmentList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("equipment:info")
    public R info(@PathVariable("id") Integer id) {
        Equipment equipment = equipmentService.queryObject(id);
        return R.success().put("equipment", equipment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("equipment:save")
    public R save(@RequestBody Equipment equipment) {
        equipmentService.save(equipment);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("equipment:update")
    public R update(@RequestBody Equipment equipment) {
        equipmentService.update(equipment);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("equipment:delete")
    public R delete(@RequestBody Integer[] ids) {
        equipmentService.deleteBatch(ids);
        return R.success();
    }


    /**
     * 列表
     */
    @RequestMapping("/onLineList")
    public R onLineList(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<Equipment> equipmentList = equipmentService.queryOnLineList(query);
        int total = equipmentService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(equipmentList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

}
